#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    void traceback(vector<int> &nums, vector<bool> &used)
    {
        if (path.size() == nums.size())
        {
            res.push_back(path);
            return;
        }
        for (int i = 0; i < (int)nums.size(); i++)
        {
            if (used[i] == true)
            {
                continue;
            }
            used[i] = true;
            path.push_back(nums[i]);
            traceback(nums, used);
            path.pop_back();
            used[i] = false;
        }
    }
    vector<vector<int>> permute(vector<int> &nums)
    {
        res.clear();
        path.clear();
        vector<bool> used(nums.size(), false);
        traceback(nums, used);
        return res;
    }
    vector<vector<int>> res;
    vector<int> path;
};

int main()
{
    vector<int> nums{1, 2, 3};
    Solution sol;
    vector<vector<int>> res = sol.permute(nums);
    for (auto vec : res)
    {
        for (auto num : vec)
        {
            cout << num << " ";
        }
        cout << endl;
    }
    return 0;
}